package com.youyi.yyviewsdklibrary.Dialog.animator;

import android.animation.IntEvaluator;
import android.animation.ValueAnimator;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;

public class ScrollScaleAnimator extends PopupAnimator {
    private IntEvaluator intEvaluator = new IntEvaluator();
    public boolean isOnlyScaleX = false;
    private float startAlpha = 0.0f;
    private float startScale = 0.0f;
    private int startScrollX;
    private int startScrollY;

    public ScrollScaleAnimator(View view, int i, PopupAnimation popupAnimation) {
        super(view, i, popupAnimation);
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator
    public void initAnimator() {
        this.targetView.setAlpha(this.startAlpha);
        this.targetView.setScaleX(this.startScale);
        if (!this.isOnlyScaleX) {
            this.targetView.setScaleY(this.startScale);
        }
        this.targetView.post(new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator.AnonymousClass1 */

            public void run() {
                ScrollScaleAnimator.this.applyPivot();
                ScrollScaleAnimator.this.targetView.scrollTo(ScrollScaleAnimator.this.startScrollX, ScrollScaleAnimator.this.startScrollY);
            }
        });
    }



    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void applyPivot() {
        switch (popupAnimation.ordinal()) {
            case 1:
                this.targetView.setPivotX(0.0f);
                this.targetView.setPivotY((float) (this.targetView.getMeasuredHeight() / 2));
                this.startScrollX = this.targetView.getMeasuredWidth();
                this.startScrollY = 0;
                return;
            case 2:
                this.targetView.setPivotX(0.0f);
                this.targetView.setPivotY(0.0f);
                this.startScrollX = this.targetView.getMeasuredWidth();
                this.startScrollY = this.targetView.getMeasuredHeight();
                return;
            case 3:
                this.targetView.setPivotX((float) (this.targetView.getMeasuredWidth() / 2));
                this.targetView.setPivotY(0.0f);
                this.startScrollY = this.targetView.getMeasuredHeight();
                return;
            case 4:
                this.targetView.setPivotX((float) this.targetView.getMeasuredWidth());
                this.targetView.setPivotY(0.0f);
                this.startScrollX = -this.targetView.getMeasuredWidth();
                this.startScrollY = this.targetView.getMeasuredHeight();
                return;
            case 5:
                this.targetView.setPivotX((float) this.targetView.getMeasuredWidth());
                this.targetView.setPivotY((float) (this.targetView.getMeasuredHeight() / 2));
                this.startScrollX = -this.targetView.getMeasuredWidth();
                return;
            case 6:
                this.targetView.setPivotX((float) this.targetView.getMeasuredWidth());
                this.targetView.setPivotY((float) this.targetView.getMeasuredHeight());
                this.startScrollX = -this.targetView.getMeasuredWidth();
                this.startScrollY = -this.targetView.getMeasuredHeight();
                return;
            case 7:
                this.targetView.setPivotX((float) (this.targetView.getMeasuredWidth() / 2));
                this.targetView.setPivotY((float) this.targetView.getMeasuredHeight());
                this.startScrollY = -this.targetView.getMeasuredHeight();
                return;
            case 8:
                this.targetView.setPivotX(0.0f);
                this.targetView.setPivotY((float) this.targetView.getMeasuredHeight());
                this.startScrollX = this.targetView.getMeasuredWidth();
                this.startScrollY = -this.targetView.getMeasuredHeight();
                return;
            default:
                return;
        }
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator
    public void animateShow() {
        this.targetView.post(new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator.AnonymousClass2 */

            public void run() {
                ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
                ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    /* class com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator.AnonymousClass2.AnonymousClass1 */

                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        float animatedFraction = valueAnimator.getAnimatedFraction();
                        ScrollScaleAnimator.this.targetView.setAlpha(animatedFraction);
                        ScrollScaleAnimator.this.targetView.scrollTo(ScrollScaleAnimator.this.intEvaluator.evaluate(animatedFraction, Integer.valueOf(ScrollScaleAnimator.this.startScrollX), (Integer) 0).intValue(), ScrollScaleAnimator.this.intEvaluator.evaluate(animatedFraction, Integer.valueOf(ScrollScaleAnimator.this.startScrollY), (Integer) 0).intValue());
                        ScrollScaleAnimator.this.targetView.setScaleX(animatedFraction);
                        if (!ScrollScaleAnimator.this.isOnlyScaleX) {
                            ScrollScaleAnimator.this.targetView.setScaleY(animatedFraction);
                        }
                    }
                });
                ofFloat.setDuration((long) ScrollScaleAnimator.this.animationDuration).setInterpolator(new FastOutSlowInInterpolator());
                ofFloat.start();
            }
        });
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator
    public void animateDismiss() {
        if (!this.animating) {
            ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
            observerAnimator(ofFloat);
            ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator.AnonymousClass3 */

                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    float animatedFraction = valueAnimator.getAnimatedFraction();
                    float f = 1.0f - animatedFraction;
                    ScrollScaleAnimator.this.targetView.setAlpha(f);
                    ScrollScaleAnimator.this.targetView.scrollTo(ScrollScaleAnimator.this.intEvaluator.evaluate(animatedFraction, (Integer) 0, Integer.valueOf(ScrollScaleAnimator.this.startScrollX)).intValue(), ScrollScaleAnimator.this.intEvaluator.evaluate(animatedFraction, (Integer) 0, Integer.valueOf(ScrollScaleAnimator.this.startScrollY)).intValue());
                    ScrollScaleAnimator.this.targetView.setScaleX(f);
                    if (!ScrollScaleAnimator.this.isOnlyScaleX) {
                        ScrollScaleAnimator.this.targetView.setScaleY(f);
                    }
                }
            });
            ofFloat.setDuration((long) this.animationDuration).setInterpolator(new FastOutSlowInInterpolator());
            ofFloat.start();
        }
    }
}
